<?php 
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/
defined('_JEXEC') or die('Restricted access'); 
?>
<?php JHTML::_('behavior.tooltip');?>

<script type="text/javascript" language="javascript">
//<![CDATA[
function submitbutton(pressbutton) {
	var form = document.adminForm;

	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	if ( pressbutton == 'save' || pressbutton == 'apply' ){
		if(form.FeedName.value == '' ){
		    alert('<?php echo JText::_('FEED NAME COULD NOT BE EMPTY')?>');
			form.FeedName.focus();
			return;
		}
		if(form.xml_sample__.value == ''){
			if(form.xml_sample.value == ''){
			    alert('<?php echo JText::_('SAMPLE FILE COULD NOT BE EMPTY')?>');
				form.xml_sample.focus();
				return;
			}
		}
		
		if(form.xml_sample.value != '' && form.xml_sample.value.indexOf(".xml") < 0){
			alert("Supported sample files with .xml extension only!");
			form.xml_sample.focus();
			return;
		}
		
		var pickup_method = getSelectedRadioValue(form.Method);
		
		switch (pickup_method){
			case "URL" :{
				if(form.FeedURL.value == '' ){
				    alert('<?php echo JText::_('FEED URL COULD NOT BE EMPTY')?>');
					form.FeedURL.focus();
					return;
				}
				break;
			}
			case "FILE" :{
				if(form.FeedFileName.value == '' ){
				    alert('<?php echo JText::_('FEED FILE NAME COULD NOT BE EMPTY')?>');
					form.FeedFileName.focus();
					return;
				}
				break;
			}
			case "FTP" :{
				if(form.FTPFileName.value == '' ){
				    alert('<?php echo JText::_('FTP FILE NAME COULD NOT BE EMPTY')?>');
					form.FTPFileName.focus();
					return;
				}
				
				if(form.FTPHost.value == '' ){
				    alert('<?php echo JText::_('FTP HOST COULD NOT BE EMPTY')?>');
					form.FTPHost.focus();
					return;
				}
				
				if(form.FTPUser.value == '' ){
				    alert('<?php echo JText::_('FTP USER COULD NOT BE EMPTY')?>');
					form.FTPUser.focus();
					return;
				}
				
				if(form.FTPPass.value == '' ){
				    alert('<?php echo JText::_('FTP PASSWORD COULD NOT BE EMPTY')?>');
					form.FTPPass.focus();
					return;
				}
				break;
			}
		}
		
		submitform( pressbutton );
	}					
	else {
		submitform( pressbutton );
	}
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function
//]]>
</script>
<form action="index.php" method="post" name="adminForm" enctype="multipart/form-data" id="adminForm">
<div class="col100">
	<?php echo $this->menu_User();?>
        	<br/>
	<fieldset class="adminform">	
		<legend><?php echo JText::_( 'BASIC FEED INFO' ); ?></legend>
		<table class="admintable" width="100%" border="1px" style="border-collapse:collapse;  border-color:#CCCCCC" cellspacing="2" cellpadding="4">
		<tr>
			<td width="100" align="right" class="key">
				<label for="feed_name">
					<?php echo JText::_( 'FEED NAME' ); ?> <span style="color:red;">*</span>:
				</label>
			</td>
			<td>
			<input type="text" name="FeedName" id="FeedName" size="70" value="<?php echo $this->data->FeedName;?>">
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="description">
					<?php echo JText::_( 'FEED DESCRIPTION' ); ?>:
				</label>
			</td>
			<td>
			<textarea name="Description" id="Description" rows="5" cols="40"><?php echo $this->data->Description;?></textarea>
			</td>
		</tr>
		
		<tr>
			<td width="100" align="right" class="key">
				<label for="ip_allow">
					<?php echo JText::_( 'XML SAMPLE FILE' ); ?>:
				</label>
			</td>
			<td>
			<i><?php echo JText::_("SAMPLE ONLY, DO NOT EDIT THE FIELD BELOW");?> </i><br><textarea disabled="disabled" name="xml_sample_" rows="4" cols="80"><?php echo ($this->data->SampleString); ?></textarea>
			<input name="xml_sample__" value="<?php echo htmlentities($this->data->SampleString); ?>" type="hidden"><input name="xml_sample_exists" value="1" type="hidden"><br>
			<input name="xml_sample" type="file"/> 
			<span class="editlinktip hasTip" title="<?php echo JText::_( 'Please upload an XML file with some sample data. The sample should contain only job 1 record.' ); ?>">
				<img border="0" alt="Tooltip" src="<?php global $mainframe; echo $mainframe->getSiteURL()?>/includes/js/ThemeOffice/tooltip.png"/> 
			</span> 
			</td>
		</tr>
		</table>
		</fieldset>
		<fieldset class="adminform">	
		<legend><?php echo JText::_( 'Feed pickup-method' ); ?></legend>
		<table class="admintable" width="100%" border="1px" style="border-collapse:collapse;  border-color:#CCCCCC" cellspacing="2" cellpadding="4">
		<tr>
			<td width="100" align="right" class="key">
				<span class="editlinktip hasTip" title="<?php echo JText::_( 'FETCH FROM URL' ); ?>::<?php echo JText::_( 'If this method is selected, then the XML feed will be read from the specified URL.' ); ?>">
					<?php echo JText::_( 'FETCH FROM URL' ); ?>: 
				</span>	
			</td>
			<td>
			<input name="Method" <?php if($this->data->Method == "URL") echo 'checked="checked"'; ?> value="URL" checked="checked" type="radio" id="FeedURL-Method"><label for="FeedURL-Method"><?php echo JText::_("FROM A URL");?></label><br>
			<input size="50" name="FeedURL" value="<?php echo $this->data->FeedURL; ?>" type="text">
			<small>(<?php echo JText::_('Eg.')?> http://www.joomlart.com/export.xml)</small>
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<span class="editlinktip hasTip" title="<?php echo JText::_( 'FETCH FROM FILE' ); ?>::<?php echo JText::_( 'If this method is selected, then the XML feed will be read from a local file.' ); ?>">
					<?php echo JText::_( 'FETCH FROM FILE' ); ?>: 
				</span>
			</td>
			<td>
			<input name="Method" <?php if($this->data->Method == "FILE") echo 'checked="checked"'; ?> value="FILE" type="radio" id="pickup_method_file"><label for="pickup_method_file"><?php echo JText::_("FROM A LOCAL FILE");?></label><br>
			<input size="50" name="FeedFileName" value="<?php echo $this->data->FeedFileName; ?>" type="text">
			<small>(<?php echo JText::_('Eg.')?> \home\www\jobboard\)</small>
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<span class="editlinktip hasTip" title="<?php echo JText::_( 'FTECH USING FTP' ); ?>::<?php echo JText::_( 'If this method is selected, then the XML feed will be fetched from another server via FTP.' ); ?>">
					<?php echo JText::_( 'FTECH USING FTP' ); ?>: 
				</span>
			</td>
			<td>
			<input name="Method" <?php if($this->data->Method == "FTP") echo 'checked="checked"'; ?> value="FTP" type="radio" id="Method-host"><label for="Method-host"><?php echo JText::_("FROM A REMOTE FTP SERVER");?></label><br>
			<?php echo JText::_("HOSTNAME:");?> <input size="20" name="FTPHost" value="<?php echo $this->data->FTPHost; ?>" type="text"> <br>
			<?php echo JText::_("USERNAME");?>: <input size="20" name="FTPUser" value="<?php echo $this->data->FTPUser; ?>" type="text"> <br>
			<?php echo JText::_("PASSWORD");?>: <input size="20" name="FTPPass" value="<?php echo $this->data->FTPPass; ?>" type="password"> <br>
			<?php echo JText::_("PATH TO XML FILE");?>: <input size="50" name="FTPFileName" value="<?php echo $this->data->FTPFileName; ?>" type="text">
			<small>(<?php echo JText::_('Eg.')?> /home/user/jajobboard.xml)</small>			
			</td>
		</tr>
	</table>
	</fieldset>
</div>
<div class="clr"></div>

<input type="hidden" name="option" value="com_jajobboard" />
<input type="hidden" name="FeedID" value="<?php echo $this->data->FeedID;?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="tab" value="feeds" />
<input type="hidden" name="view" value="jaxmlimport" />
</form>